<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> UDT Reference</title>
<link rel="stylesheet" href="udtdoc.css" type="text/css" />
</head>

<body>
<div class="ref_head">&nbsp;UDT Reference: Functions</div>

<h4 class="func_name"><strong>getpeername</strong></h4>
<p>The <b>getpeername</b> method retrieves the address informtion of the peer side of a connected UDT socket.</p>

<div class="code">int getpeername(<br />
&nbsp; UDTSOCKET <font color="#FFFFFF">u</font>,<br />
&nbsp; struct sockaddr* <font color="#FFFFFF">name</font>,<br />
&nbsp; int* <font color="#FFFFFF">namelen</font><br />
);</div>

<h5>Parameters</h5>
<dl>
  <dt><i>u</i></dt>
  <dd>[in] Descriptor identifying a connected socket.</dd>
  <dt><em>name</em></dt>
  <dd>[out] The structure to store the address of the peer.</dd>
  <dt><em>addrlen</em></dt>
  <dd>[in, out] pointer to the size of the <i>name</i> structure.</dd>
</dl>

<h5>Return Value</h5>
<p>On success, <strong>getlasterror</strong> returns 0 and the peer address information is stored in <i>name</i>; otherwise it returns UDT::ERROR and the specific error information can be 
retrieved using <a href="error.htm">getlasterror</a>.</p>

<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td width="17%" class="table_headline"><strong>Error Name</strong></td>
    <td width="17%" class="table_headline"><strong>Error Code</strong></td>
    <td width="83%" class="table_headline"><strong>Comment</strong></td>
  </tr>
  <tr>
    <td>ENOCONN</td>
    <td>2002</td>
    <td><i>u</i> is not connected.</td>
  </tr>
  <tr>
    <td>EINVPARAM</td>
    <td>5003</td>
    <td>Invalid parameters.</td>
  </tr>
  <tr>
    <td>EINVSOCK</td>
    <td>5004</td>
    <td><i>u</i> is an invailid UDT socket.</td>
  </tr>
</table>

<h5>Description</h5>
<p>The <strong>getpeername</strong> retrieves the address of the peer side associated to the connection. The UDT socket must be connected at the time when this method is called. The 
<i>namelen</i> must provide the leangth of the <i>name</i> parameter, which should be enough to hold the address information. On return, <i>namelen</i> contains the length of the result.</p>

<h5>See Also</h5>
<p><strong><a href="listen.htm">listen</a>, <a href="connect.htm">connect</a>, <a href="accept.htm">accept</a></strong></p>
<p>&nbsp;</p>

</body>
</html>
